﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using TMPro;
using UnityEngine;

public class TopUIManager : MonoBehaviour
{
    public TextMeshProUGUI turnText;
    public TextMeshProUGUI lifeText;
    public TextMeshProUGUI moneyText;
    public TextMeshProUGUI turnNameText;
    public TextMeshProUGUI deckCardNumText;

    private void Awake()
    {
        PlayerProxier playerProxier = GameObject.FindObjectOfType<PlayerProxier>();
    }

    private void Start()
    {
        transform.SetAsLastSibling();
        
        PlayerProxier playerProxier = GameObject.FindObjectOfType<PlayerProxier>();
        
        playerProxier.LifeCheckListener += FlushLifeText;
        playerProxier.MoneyCheckListener += FlushMoneyText;
        playerProxier.DeckCardNumListener += FlushDeckCardNumText;
        
        TurnManager.turnStringListener += FlushTurnNameText;
        TurnManager.turnNumListener += FlushTurnText;
        
        GameObject.FindGameObjectWithTag(StaticDataManager.GAME_SESSION_TAG).GetComponent<UIFlusher>().FlushAllUIElement();
    }

    public void FlushDeckCardNumText(int num)
    {
        deckCardNumText.SetText(num.ToString());
    }
    
    public void FlushMoneyText(int num)
    {
        moneyText.SetText(num.ToString());
    }
    
    public void FlushTurnText(int num)
    {
        turnText.SetText(new StringBuilder($"当前回合数：{num.ToString()}"));
    }

    public void FlushTurnNameText(string turnBelong)
    {
        turnNameText.SetText(new StringBuilder($"当前的回合属于 {turnBelong}").ToString());
    }
    
    public void FlushLifeText(int currentLife, int maxLife)
    {
        lifeText.SetText($"{currentLife} / {maxLife}");
    }
}
